import { Route, Redirect } from 'react-router-dom'
import { getToken } from '../utils/token'
export default function AuthRouter({ path, component: Com, ...rest }) {
  return (
    <Route path={path} {...rest} render={(props) => {
      const token = getToken()
      if (token) {
        return <Com {...props} />
      } else {
        <Redirect to='/' state={{ form: props.location.pathname }} />
      }
    }}>
    </Route>
  )
}